<?php
// -----------------------------------------------------------------------------
// include
// -----------------------------------------------------------------------------

include "../config/config.php";
include "../auth.php";
include "../DBManager.php";

// -----------------------------------------------------------------------------
// 数据库相关设置
// -----------------------------------------------------------------------------

$dbPath = "../" . $dbPath; // 不加这行语句的话会报错，提示找不到对应路径
$db = new DBManager("sqlite:" . $dbPath);

// -----------------------------------------------------------------------------
?>
<html lang="zh">
<head>
    <meta charset="utf-8">
    <title><?php echo $linkTitleSpecific; ?></title>
    <base target="_self">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="../resources/bootstrap-5.2.0-beta1-dist/css/bootstrap.min.css">
</head>
<body>

<!-- ----------------------------------------------------------------------- -->

<script src="../resources/bootstrap-5.2.0-beta1-dist/js/bootstrap.min.js"></script>
<script src="../resources/jQuery/jquery-3.5.1.js"></script>
<?php include "../globalNavbar.php"; ?>

<!-- ----------------------------------------------------------------------- -->

<!--div:container start-->
<div class="container container-fluid mb-5">


    <!-- 导航栏 开始 -->
    <div class="mt-3">
        <nav style="--bs-breadcrumb-divider: '>';" aria-label="breadcrumb">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a class="text-decoration-none" href="<?php echo $homepage; ?>">首页</a></li>
                <li class="breadcrumb-item active"><?php echo $linkTitleSpecific; ?></li>
            </ol>
        </nav>
    </div>
    <!-- 导航栏 结束 -->

    <!-- ------------------------------------------------------------------- -->

    <div class="mt-2">
        <h3>指定日</h3>
        <div class="input-group mb-3">
            <input id="inputDate" name="date" type="date" autofocus class="form-control">
            <button class="btn btn-outline-secondary" type="button" id="btnViewSpecificDate">查看</button>
        </div>
    </div>

    <!-- ------------------------------------------------------------------- -->

    <div class="mt-2">
        <h3>本周</h3>
        <div class="list-group">
            <a href="weekView.php?from=thisWeek" class="list-group-item list-group-item-action">查看</a>
        </div>
    </div>

    <div class="mt-2">
        <h3>下周</h3>
        <div class="list-group">
            <a href="weekView.php?from=nextWeek" class="list-group-item list-group-item-action">查看</a>
        </div>
    </div>

    <div class="mt-2">
        <h3>指定周</h3>
        <div class="input-group mb-3">
            <input id="inputWeek" name="week" type="date" class="form-control">
            <button class="btn btn-outline-secondary" type="button" id="btnViewSpecificWeek">查看</button>
        </div>
    </div>

    <!-- ------------------------------------------------------------------- -->

    <div class="mt-2">
        <h3>本月</h3>
        <div class="list-group">
            <a href="monthView.php?from=thisMonth" class="list-group-item list-group-item-action">查看</a>
        </div>
    </div>

    <div class="mt-2">
        <h3>下月</h3>
        <div class="list-group">
            <a href="monthView.php?from=nextMonth" class="list-group-item list-group-item-action">查看</a>
        </div>
    </div>

    <div class="mt-2">
        <h3>指定月</h3>
        <div class="input-group mb-3">
            <input id="inputMonth" name="month" type="month" class="form-control">
            <button class="btn btn-outline-secondary" type="button" id="btnViewSpecificMonth">查看</button>
        </div>
    </div>

    <!-- ------------------------------------------------------------------- -->

</div>
<!--div:container end-->

<!-- ----------------------------------------------------------------------- -->

<script>

    $("#btnViewSpecificDate").on("click", function () {
        var inputedDate = $("#inputDate").val()
        if (inputedDate !== "") {
            var arr = inputedDate.split("-")
            inputedDate = arr[0] + arr[1] + arr[2]
            var url = "../viewByDate.php?date=" + inputedDate
            window.open(url, "_self")
        } else {
            alert("请先选择日期。")
        }
    })

</script>

<!-- ----------------------------------------------------------------------- -->

<script>

    $("#btnViewSpecificWeek").on("click", function () {
        var inputtedDate = $("#inputWeek").val()
        if (inputtedDate !== "") {
            var arr = inputtedDate.split("-")
            inputtedDate = arr[0] + arr[1] + arr[2]
            var url = `weekView.php?from=date&date=${inputtedDate}`
            window.open(url, "_self")
        } else {
            alert("请先选择要查看的周。")
        }
    })

</script>

<!-- ----------------------------------------------------------------------- -->

<script>

    $("#btnViewSpecificMonth").on("click", function () {
        var inputtedMonth = $("#inputMonth").val()
        if (inputtedMonth !== "") {
            var arr = inputtedMonth.split("-")
            var year = arr[0]
            var month = arr[1]
            var url = `monthView.php?year=${year}&month=${month}`
            window.open(url, "_self")
        } else {
            alert("请先选择月份。")
        }
    })

</script>

<!-- ----------------------------------------------------------------------- -->

</body>
</html>
